<%@page pageEncoding="utf-8" import="java.util.*,com.pmc.dwa.common.utils.ConfigParameter" contentType="text/html; charset=utf-8" %>
<%
String sysMainName = ConfigParameter.getParamVal("sysconf.properties","sysMainName");
String sysSubName = ConfigParameter.getParamVal("sysconf.properties","sysSubName");
String sysVersion = ConfigParameter.getParamVal("sysconf.properties","sysVersion");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=sysMainName%>-<%=sysSubName%> <%=sysVersion%></title>
	<%@ include file="/common/view/header.jsp"%>
	<script>
	var win=null, win2=null, form_uptpwd=null, form_uptinfo=null, form=null;
	$(function(){
		var href = "<%=cp%>/common/view/leftmenu.jsp";
		var p = $('body').layout('panel','west').panel({
			content:'<iframe scrolling="no" frameborder="0" src="'+href+'" style="width:100%;height:100%;"></iframe>'
		});
		
		//获取登录用户信息
		$.ajax({
			type: "GET",
			url: "<%=cp%>/rbac/getLoginUser?rnd="+Math.random(),
			dataType: "json",
			success: function(data) {
				var odata		= eval(data);
				var uid			= odata.userid;
				var uname		= odata.username;
				var loginip		= odata.last_loginip;
				var logintime	= odata.last_logintime;
				var userRoles	= odata.userRoles;
				var userSection	= odata.userSection;
				var roleComments = "";
				if(userRoles.length>0){
					roleComments = userRoles[0].comments;
				}
				if(uid != "0"){
					$("#loginUsername")[0].innerHTML = uname + "("+roleComments+")";
					$("#userinfo")[0].innerHTML = "欢迎您,"+uname+"! 最近登录IP:"+loginip+" / 最近登录时间:"+logintime+"";
				}else{
					$("#userinfo")[0].innerHTML = "匿名用户访问中，请您先登录系统。"
				}
				//if(userSection != null){
				//	$("#sectionInfo")[0].innerHTML = userSection.name;
				//}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert(textStatus);
			}
		});
		init_window();
		init_window2();
		init_form();
	});
	/* 初始化窗口控件 */
	function init_window(){
		var width = 380;
		var height = 200;
		var top = (document.body.clientHeight-height)/2;
		var left = (document.body.clientWidth-width)/2;
		win = $('#uptpwd_win').window({
			closed:true,
			width: width,
			height: height,
			top: top,
			left: left,
			modal: true,
			minimizable:false,
			maximizable:false,
			collapsible:false,
			resizable:false,
			iconCls:'icon-vcard'
		});
	}
	function init_window2(){
		var width = 560;
		var height = 220;
		var top = (document.body.clientHeight-height)/2;
		var left = (document.body.clientWidth-width)/2;
		win2 = $('#userinfo_win').window({
			closed:true,
			width: width,
			height: height,
			top: top,
			left: left,
			modal: true,
			minimizable:false,
			maximizable:false,
			collapsible:false,
			resizable:false,
			iconCls:'icon-vcard'
		});
	}
	/* 初始化表单控件 */
	function init_form(){
		form_uptpwd = win.find('form');
		form_uptinfo = win2.find('form');
	}
	function uptPwd(){
		$('#uptpwd_win')[0].style.display = "block";
		win.window('setTitle','修改密码');
		win.window('open');
		form_uptpwd.form('clear');
		form_uptpwd.url = '<%=cp%>/rbac/uptPwd?rnd='+Math.random();
		form = form_uptpwd;
	}
	function uptUserinfo(){
		$('#userinfo_win')[0].style.display = "block";
		win2.window('setTitle','更新个人信息');
		win2.window('open');
		form_uptinfo.form({
			onLoadError:function(XMLHttpRequest, textStatus, errorThrown){
				$.messager.alert('错误','登录超时，请您重新登录！','error');
			}
		});
		form_uptinfo.form('clear');
		form_uptinfo.form('load', '<%=cp%>/rbac/getLoginUser?rnd='+Math.random());
		form_uptinfo.url = '<%=cp%>/rbac/uptLoginUser?rnd='+Math.random();
		form = form_uptinfo;
	}
	function closeWindow(){
		if(win)
			win.window('close');
		if(win2)
			win2.window('close');
	}
	/* 保存数据 */
	function do_saveData(){
		form.form('submit', {
			url:form.url,
			onSubmit:function(){  
				return $(this).form('validate');
			},
			success:function(data){
				data = unescape(data);
				eval('data='+data);
				if (data.success=='true'){
					if(data.action=='uptpwd'){
						$.messager.alert('更新提示','您的密码已经更新成功，请您重新登录系统。','info',function(){window.location.href='<%=cp%>/j_spring_security_logout';});
					}else{
						$.messager.alert('更新提示','您的个人资料更新成功！','info');
					}
					closeWindow();
				} else {
					$.messager.alert('错误',data.msg,'error');
				}
			}
		});
	}
	function addTab(title, href){
		var tt = $('#main-center');
		if (tt.tabs('exists', title)){
			tt.tabs('select', title);
		} else {
			if (href){
				var content = '<iframe scrolling="no" frameborder="0"  src="'+href+'" style="width:100%;height:100%;"></iframe>';
			} else {
				var content = '未实现';
			}
			tt.tabs('add',{
				title:title,
				closable:true,
				content:content
			});
		}
	}
	function showMapTab(){
		addTab("GIS展示", "<%=cp%>/map/index.html");
		return window.frames['map_iframe'];
	}
	/* 显示时钟 */
	function showTime(){
		var time = new Date();
		hours = time.getHours();
		minutes = time.getMinutes();
		seconds = time.getSeconds();
		year = time.getFullYear();
		month = time.getMonth() + 1;
		date = time.getDate();
		day = time.getDay();
		dayArray = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
		if(minutes<=9)
			minutes = "0"+minutes;
		if(seconds<=9)
			seconds = "0"+seconds;
		theTime = year + "年" + month + "月" + date + "日 " + dayArray[day] + "&nbsp;&nbsp;" + hours + ":" + minutes + ":" + seconds;
		$('#DT')[0].innerHTML = theTime;
		setTimeout("showTime()",1000);
	}
	/* 切换视图 */
	function fullview(mod){
		var btnfullview = $("#btnfullview")[0];
		var btnframeview = $("#btnframeview")[0];
		if(mod=='full'){
			//全屏视图
			$('body').layout('collapse','north');
			$('body').layout('collapse','west');
			btnfullview.style.display = 'none';
			btnframeview.style.display = 'block';
		}else if(mod=='frame'){
			//框架视图
			$('body').layout('expand','north');
			$('body').layout('expand','west');
			btnfullview.style.display = 'block';
			btnframeview.style.display = 'none';
		}
	}
	window.onload = function(){
		showTime();
	}
	</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north'" border="false" id="header">
		<div class="leftarea"><img src="<%=cp%>/common/images/header.jpg" width="666" height="60" border="0" /></div>
		<div class="rightarea">
		  <div>
			<a href="javascript:void(0)" id="mb0" class="easyui-menubutton" menu="#mm0" icon="icon-greenuser"><span id="loginUsername" class="headerfont" onMouseOver="this.className='headerfont2'" onMouseOut="this.className='headerfont'">Loading...</span></a>
			<div id="mm0" style="width:100px;display:none;">
				<div><a href="javascript:void(0)" onclick="javascript:uptPwd();" class="amenu">修改密码</a></div>
				<div><a href="javascript:void(0)" onclick="javascript:uptUserinfo();" class="amenu">修改资料</a></div>
			</div>
			<a href="javascript:void(0)" id="mb1" class="easyui-menubutton" menu="#mm1" icon="icon-no"><span class="headerfont" onMouseOver="this.className='headerfont2'" onMouseOut="this.className='headerfont'">注销</span></a>
			<div id="mm1" style="width:100px;display:none;">
				<div><a href="<%=cp%>/j_spring_security_logout" target="_top" onClick="javascript:return confirm('您确定要退出系统吗？');" class="amenu">退出系统</a></div>
			</div>
			<a href="javascript:void(0)" id="mb2" class="easyui-menubutton" menu="#mm2" icon="icon-help"><span class="headerfont" onMouseOver="this.className='headerfont2'" onMouseOut="this.className='headerfont'">帮助</span></a>		
			<div id="mm2" style="width:100px;display:none;">
				<div><a href="javascript:alert('系统帮助文档正在撰写中...')" class="amenu">系统帮助</a></div>
				<div><a href="javascript:alert('系统名称：<%=sysMainName%>-<%=sysSubName%>\n当前版本：<%=sysVersion%>');" class="amenu">关于系统</a></div>
			</div>
		  </div>
		  <div class="crumb"><span id="DT" class="headerfont"></span></div>
		</div>
	</div>
	<div data-options="region:'west',split:true" title="系统导航菜单" style="width:200px;"></div>
	<!-- <div region="east" split="true" title="East" style="width:100px;padding:10px;">east region</div> -->
	<div region="south" border="false" id="footer">
		<div class="leftarea"><span id="userinfo">Loading...</span></div>
		<div class="btnview">
		  <img id="btnfullview" src="<%=cp%>/common/images/image.png" vspace="1" title="切换到地图全屏视图" border="0" style="cursor:pointer; display:block;" onclick="javascript:fullview('full');" />
		  <img id="btnframeview" src="<%=cp%>/common/images/images.png" vspace="1" title="切换到布局框架视图" border="0" style="cursor:pointer; display:none;" onclick="javascript:fullview('frame');" />
		</div>
		<div class="rightarea">Powered by SystemFramework &copy; 2013 Peacemap Inc.</div>
	</div>
	<div data-options="region:'center'">
		<div id="main-center" class="easyui-tabs" fit="true" border="false">
			<div title="GIS展示" data-options="iconCls:'icon-network',closable:false">
				<iframe id="map_iframe" name="map_iframe" scrolling="no" frameborder="0" src="<%=cp%>/map/index.html" style="width:100%;height:100%;"></iframe>
			</div>
		</div>
	</div>
	<!-- update password form -->
	<div id="uptpwd_win" class="easyui-window" style="display:none;">
	  <div style="text-align:center; padding:1px;">
	    <form id="uptpwd_form" method="post">
		  <table width="90%" cellspacing="1" cellpadding="2" border="0" align="center">
		    <tr>
		      <td align="right">当前密码：</td> 
		      <td><input type="password" name="cur_password" class="easyui-validatebox" required="true" missingMessage="请填写当前密码" /></td>
		    </tr>
		    <tr>
		      <td align="right">新密码：</td>
		      <td><input type="password" name="new_password" class="easyui-validatebox" required="true" missingMessage="请填写新密码" /></td>
		    </tr>
		    <tr>
		      <td align="right">确认密码：</td>
		      <td><input type="password" name="confirm_password" class="easyui-validatebox" required="true" missingMessage="请填写确认密码" /></td>
		    </tr>
		</table>
	    </form>
	  </div>
	  <div style="text-align:center;padding:5px;">
	    <a href="javascript:void(0)" onclick="do_saveData()" id="btn-save" class="easyui-linkbutton" icon="icon-save">修改</a>  
	    <a href="javascript:void(0)" onclick="closeWindow()" id="btn-cancel" class="easyui-linkbutton" icon="icon-cancel">取消</a>  
	  </div>
	</div>
	<!-- user info form -->
	<div id="userinfo_win" class="easyui-window" style="display:none;">
	    <div style="text-align:center; padding:1px;">
	        <form id="userinfo_form" method="post">
	            <table width="90%" cellspacing="1" cellpadding="2" border="0" align="center">
	                <tr>
	                    <td>真实姓名：</td>
	                    <td><input type="text" name="truename" class="easyui-validatebox" required="true" missingMessage="请填写真实姓名" /></td>
	                    <td>电子邮件：</td>
	                    <td><input type="text" name="email" class="easyui-validatebox" validType="email" invalidMessage="邮箱格式错误" /></td>
	                </tr>
	                <tr>
	                    <td>住宅电话：</td>
	                    <td><input type="text" name="hometel" /></td>
	                    <td>单位电话：</td>
	                    <td><input type="text" name="unittel" /></td>
	                </tr>
	                <tr>
	                    <td>手机号码：</td>
	                    <td><input type="text" name="mobileno" /></td>
	                    <td>联系地址：</td>
	                    <td><input type="text" name="addr" /></td>
	                </tr>
	            </table>
	        </form>
	    </div>
	    <div style="text-align:center;padding:5px;">
	        <a href="javascript:void(0)" onclick="do_saveData()" id="btn-save" class="easyui-linkbutton" icon="icon-save">更新</a>  
	        <a href="javascript:void(0)" onclick="closeWindow()" id="btn-cancel" class="easyui-linkbutton" icon="icon-cancel">取消</a>  
	    </div>
	</div>
</body>
</html>